<template>
  <div class="app-container">
    <el-form label-width="120px">
      <el-form-item label="医院名称">
        <el-input v-model="hospitalSet.hosname" placeholder="医院名称"></el-input>
      </el-form-item>
      <el-form-item label="医院编号">
        <el-input v-model="hospitalSet.hoscode" placeholder="医院编号"></el-input>
      </el-form-item>
      <el-form-item label="API基础路径">
        <el-input v-model="hospitalSet.apiUrl" placeholder="API基础路径"></el-input>
      </el-form-item>
      <el-form-item label="联系人姓名">
        <el-input v-model="hospitalSet.contactsName" placeholder="联系人姓名"></el-input>
      </el-form-item>
      <el-form-item label="联系人手机">
        <el-input v-model="hospitalSet.contactsPhone" placeholder="联系人手机"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="saveOrUpdate">保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import {save,updateById,getById} from '@/api/hospitalSet'

export default {
  data() {
    return {
      hospitalSet: {},
    }
  },
  created() {
    if (this.$route.params&&this.$route.params.id){
      this.getById(this.$route.params.id)
    }else {
      this.hospitalSet={}
    }
  },
  methods: {
    saveOrUpdate() {
      if (this.hospitalSet.id){
        updateById(this.hospitalSet).then(res => {
          this.$message({
            type: 'success',
            message: '修改成功!'
          })
          this.$router.push({path:"/hospitalSet/list"})
        })
      }else {
        save(this.hospitalSet).then(res => {
          this.$message({
            type: 'success',
            message: '添加成功!'
          })
          this.$router.push({path:"/hospitalSet/list"})
        })
      }

    },
    getById(id){
      getById(id).then(res=>{
        const {data} = res
        this.hospitalSet=data
      })
    }
  }
}
</script>
